package com.KsbaoTest;


import com.Log4.LogType;
import com.Log4.Logger;
//import org.apache.log4j.PropertyConfigurator;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.util.Optional;
import java.util.concurrent.TimeUnit;

public class Index {

    private ChromeDriver driver;
    Logger logger1 = new Logger();  //这个是Log包中的实例
//    private static Logger logger = Logger.getLogger(Index.class);

    @BeforeClass
    public void Up() throws InterruptedException {
        System.setProperty("webdriver.chrome.driver", "src/main/resources/chromedriver.exe");
        //打开浏览器
        driver = new ChromeDriver();
        driver.manage().window().maximize();
//      driver.get("http://smp-test.yingedu.com/");
        driver.get("https://www.ksbao.com/");
        //隐式等待10秒  如果页面加载慢就等待页面加载
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);


    }

    @Test
    public void IndexTest() throws Exception {

        //PropertyConfigurator.configure("src/log4j.properties");  // 打开这个的话会生成html文件
        WebElement test = driver.findElement(By.xpath("//*[@id=\"__layout\"]/div/div[2]/div[2]/div/div[1]/div[1]/p"));
        String text = test.getText();
        String title = "哈哈哈";
        logger1.Output(LogType.LogTypeName.INFO, "包含");

        if (text.contains("英腾教育")) {
            logger1.Output(LogType.LogTypeName.INFO, "包含");
        } else {
            logger1.Output(LogType.LogTypeName.INFO, "不包含");

        }
    }

    @Test
    public void Login() {
        String phone = "1999464705";
        driver.findElement(By.xpath("//*[@id=\"__layout\"]/div/div[1]/div[1]/div[2]/div/div[1]/span[1]")).click();
        driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
        // driver.findElement(By.xpath("//*[@id=\"pane-账号密码登录\"]/div[1]/div/input")).sendKeys("19994647052");
        driver.findElement(By.xpath("//*[@id=\"pane-账号密码登录\"]/div[1]/div/input")).sendKeys(phone);

        driver.findElement(By.xpath("//*[@id=\"pane-账号密码登录\"]/div[2]/div/input")).sendKeys("yt123465");
        ////加入断言
//        assertEqual(a,b)       断言a==b
//        assertNotEqual(a,b)    断言a!=b
//        assertTrue(a)          断言a为真
//        assertFalse (a)        断言a为假
//        assertln(a,b)          断言a在b里面
//        assertNotin(a,b)       断言a不在b里面
        try {
            //参数1：实际值  参数2：我预期的值
            Assert.assertEquals(phone, "19994647052");
        } catch (Exception e) {
            System.out.println("手机号格式错误" + e.getMessage());
        }

    }
}
